<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="../vue.js"></script>
</head>
<body>
<div id="app">
    <transition
            name="fade"
            @before-enter="handleBeforeEnter"
            @enter="handleEnter"
            @after-enter="handleAfterEnter"
            @before-leave="handleBeforeLeave"
            @leave="handleLeave"
            @after-leave="handleAfterLeave"
            >
        <div v-show="show">hello world</div>
    </transition>
    <button @click="handleClick">toggle</button>
</div>

<script>
    var vm = new Vue({
        el: "#app",
        data: {
            show:true
        },
        methods:{
            handleClick: function () {
                this.show=!this.show
            },
            handleBeforeEnter: function (el) {
                //el为动画包裹的元素
                el.style.color='red'
            },
            handleEnter: function (el,done) {
                //done回调函数
                setTimeout(() => {
                    el.style.color='green'
                },2000)
                setTimeout(()=>{
                    done()
                },4000)
            },
            handleAfterEnter: function (el) {
                el.style.color='#000'
            }
        }

    })
</script>
</body>
</html>